package shumatz;

import java.io.IOException;
import java.util.logging.Logger;
import javax.servlet.http.*;
import com.google.appengine.api.users.*;
import java.util.*;
import javax.jdo.*;


public class SignGuestBookServlet extends HttpServlet {
	private static final Logger log = Logger.getLogger(SignGuestBookServlet.class.getName());
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
	throws IOException{
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		
		String content = req.getParameter("content");
		String userName = req.getParameter("yourname");
		
		Date date = new Date();
		List<String> list = new ArrayList<String>();
		list.add("one");
		list.add("two");
		list.add("three");
		
		Greeting greeting = new Greeting(user, userName, content, date, list);
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try{
			pm.makePersistent(greeting);
		}finally{
			pm.close();
		}
		resp.sendRedirect("/");
		
//		if (content == null){
//			content = "(No Greeting)";
//			
//		}
//		if (user != null){
//			log.info("Greeting posted by user" + user.getNickname() + ": " + content);
//			
//		} else {
//			log.info("Greeting posted anonymously: " + content);
//		}
		
	}

}
